﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Prism.Collections.Generic;
using Prism.Collections.ObjectModel;

namespace Prism.Games.GalEngine.Scripts.FunctionModel
{
    [Serializable]
    public class ItemIncrementalMarkedTree<NodeType, ValueType> : ObservableTree<NodeType, ValueType>, ICounter
        where NodeType : TreeNode<ValueType>
        where ValueType : IId
    {
        public ItemIncrementalMarkedTree()
            : base()
        {
            this.Counter = -1;
        }

        public override void Add(NodeType parentNode, NodeType childNode, ValueType value)
        {
            base.Add(parentNode, childNode, value);
            this.Counter++;
            value.Id = this.Counter;
        }

        public void Add(NodeType parentNode, NodeType childNode, ValueType value, bool doNotSortId)
        {
            if (doNotSortId)
                base.Add(parentNode, childNode, value);
            else this.Add(parentNode, childNode, value);
        }

        public int Counter { get; set; }
    }
}
